#!/bin/sh
source /etc/profile

basepath=$DEPLOY_HOME/asap-rule-engine
cd $basepath/bin
hostName=`hostname -f`
id=`cat $basepath/log/ruleEnginerTaskId.log`
pid=`yarn application --list|grep asapRuleEnginer|awk '{print $1}'`

if [ -n "$pid" ] ; then
        echo "ruleEngine is RUNNING"
else
        `rm -f $hostName/conf/start-engine.json`
        `python ruleEnginerjson.py`
        curl -X POST -H "Content-Type: application/json"  $hostName:8998/batches --data @$basepath/conf/start-engine.json | python -c 'import sys,json;print json.load(sys.stdin)["id"]' > $basepath/log/ruleEnginerTaskId.log
fi